﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Mang
{
    public class SelectionSort<T> : ThuatToanSapXep<T> where T : IComparable
    {
        //Sap Xep giam dan
        public override void SapXep(T[] a, int n)
        {
            for (int i = 0; i < n - 1; i++)
            {
                for (int j = i + 1; j < n; j++)
                {
                    if (a[i].CompareTo(a[j]) < 0)
                    {
                        HoanVi(ref a[i], ref a[j]);
                    }
                }
            }
        }

        //Sap Xep giam dan
        public override void SapXep(T[] a, int n, TieuChiSapXep<T> tc)
        {
            for (int i = 0; i < n - 1; i++)
            {
                for (int j = i + 1; j < n; j++)
                {
                    if (tc.Compare(a[i], a[j]) < 0)
                    {
                        HoanVi(ref a[i], ref a[j]);
                    }
                }
            }
        }
    }
}
